Label control is used to display Text on the Form. Main property of the label control is the text property which is used to set the text in the label.
How to use Label Control
Drag and drop Label control from the toolbox on the window Form.
Display Text in Label.
private void Form8_Load(object sender, EventArgs e)
{
// display text in Label
label1.Text = "Hello";
}
The text will display in Label when the Application run.
Label Properties:
Text: The text that appears on the Label control.
Enabled: If this property is set to false, the Label appears grayed out.
private void Form8_Load(object sender, EventArgs e)
{
//disable Label
label1.Enabled = false;
}
BackColor: Set the background color of Label control.
private void Form8_Load(object sender, EventArgs e)
{
//change Label BackColor
label1.BackColor = Color.CadetBlue;
}
Output
ForeColor: Set the ForeColor of Label control.
private void Form8_Load(object sender, EventArgs e)
{
// change ForeColor of Label's text
label1.ForeColor = Color.Red;
}
Output
Leave Comment